package peer.p2pnet.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteIntSwitch;
import peer.tools.ByteShortSwitch;

public class ExitMessage extends Message{
	public short sType=peer.tools.MessageType.sType_ExitMessage;
	int sessionId =0;
	byte[] dpData=new byte[8];
	public ExitMessage(){
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		
		ByteIntSwitch.toByteArray(sessionId, dpData, 4);  //add: sessionId
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public void setSessionId(int sessionId){
		this.sessionId=sessionId;
		ByteIntSwitch.toByteArray(this.sessionId, dpData, 4);  //add: sessionId
	}
	
	public int getSessionId (){
		return sessionId ;
	}
	
	public ExitMessage(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		sessionId=ByteIntSwitch.toInt(dpData, 4);
	}
}
